/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_MAKECARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H
#define SWANLINK_FINANCE_MAKECARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H

#define CONFIG_HILOG
#ifdef CONFIG_HILOG
#include "hilog/log.h"
namespace SwanLink {
namespace Finance {
#define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__

#ifdef MAKECARD_HILOGF
#undef MAKECARD_HILOGF
#endif

#ifdef MAKECARD_HILOGE
#undef MAKECARD_HILOGE
#endif

#ifdef MAKECARD_HILOGW
#undef MAKECARD_HILOGW
#endif

#ifdef MAKECARD_HILOGI
#undef MAKECARD_HILOGI
#endif

#ifdef MAKECARD_HILOGD
#undef MAKECARD_HILOGD
#endif

enum MAKECARD_MODULE {
    MAKECARD_UTIL = 0,
    MAKECARD_KITS,
    MAKECARD_INNERKITS,
    MAKECARD_JS_NAPI,
    MAKECARD_SRV,
    MAKECARD_TEST,
    MAKECARD_BUTT
};
// In order to improve performance, do not check the module range.

static constexpr OHOS::HiviewDFX::HiLogLabel MAKECARD_LABEL[MAKECARD_BUTT] = {
    {LOG_CORE, MAKECARD_UTIL,            "MakecardUtils"},
    {LOG_CORE, MAKECARD_KITS,            "MakecardKits"},
    {LOG_CORE, MAKECARD_INNERKITS,       "MakecardInnerKits"},
    {LOG_CORE, MAKECARD_JS_NAPI,          "MakecardJsNapi"},
    {LOG_CORE, MAKECARD_SRV,              "MakecardSrv"},
    {LOG_CORE, MAKECARD_TEST,              "MakecardTest"}
};

// Besides, make sure module is less than POWERMGR_MODULE_BUTT.
#define MAKECARD_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(\
    MAKECARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define MAKECARD_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(\
    MAKECARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define MAKECARD_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(\
    MAKECARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define MAKECARD_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(\
    MAKECARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define MAKECARD_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(\
    MAKECARD_LABEL[module], __FORMATED(__VA_ARGS__))

}  // namespace Finance
}  // namespace SwanLink

#else

#define MAKECARD_HILOGF(...)
#define MAKECARD_HILOGE(...)
#define MAKECARD_HILOGW(...)
#define MAKECARD_HILOGI(...)
#define MAKECARD_HILOGD(...)

#endif  // CONFIG_HILOG

#endif  // SWANLINK_FINANCE_MAKECARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H
